package com.sm.sales_management.controller;

import com.sm.sales_management.domain.Purchasegoods;
import com.sm.sales_management.domain.Salesman;
import com.sm.sales_management.service.IPurchasegoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/purchasegoods")
public class PurchasegoodsController {

    @Autowired
    IPurchasegoodsService purchasegoodsService;

    @RequestMapping("/allpurchasegoods")
    public String allpurchasegoods(Model model){
        List<Purchasegoods> purchasegoodsList=purchasegoodsService.selectAllPurchasegoods();
        model.addAttribute("purchasegoodsList",purchasegoodsList);
        return "purchasegoods_list";

    }

    @RequestMapping("/delpurchasegoods{id}")
    public String delpurchasegoods(@PathVariable("id") int id){
        purchasegoodsService.delete(id);
        return "redirect:/purchasegoods/allpurchasegoods";
    }

    @RequestMapping("/toupdatepur")
    public String toupdatepur(){
        return "updatepur";
    }

    @RequestMapping("/updatepur")
    public String updatepur(Purchasegoods purchasegoods){
        purchasegoodsService.updatePurchasegoods(purchasegoods);
        return "redirect:/purchasegoods/allpurchasegoods";
    }

    @RequestMapping("/toaddpur")
    public String toaddpur(){

        return "addpurchasegoods";
    }

    @RequestMapping("/addpur")
    public String addpur(Purchasegoods purchasegoods){
        purchasegoodsService.insertPurchasegoods(purchasegoods);
        return "redirect:/purchasegoods/allpurchasegoods";
    }

}
